import Vue from 'vue'
import 'normalize.css/normalize.css'
import 'animate.css';
import Element from 'element-ui'
import './styles/element-variables.scss'
import '@/styles/index.scss'
import '@/styles/bs-common.scss'
import '@/assets/fonts/iconfont.css'
import eventBus from '@/utils/eventBus.js'
import methods from '@/utils/methods.js'
import App from './App'
import store from './store'
import router from './router'
import VueParticles from 'vue-particles'
import bsComponets from '@/components/bs-comps'
import BaiduMap from 'vue-baidu-map'
import ElSelectTree from 'el-select-tree'
import ElSelectTree_Hack from './hack/el-select-tree.js'
import './icons'
import './permission'
import './utils/error-log'
import * as filters from './filters'
import elDragDialog from './directive/el-drag-dialog'
import VueDraggableResizable from 'vue-draggable-resizable'
// optionally import default styles
import 'vue-draggable-resizable/dist/VueDraggableResizable.css'
import VScrollSync from './directive/v-scroll-sync'
import i18n from './assets/languages'
import moment from 'moment'
import 'moment/locale/zh-cn'
import XiaolijianComponent from "xiaolijian-components/lib/xiaolijian-components.umd.js";
Vue.use(XiaolijianComponent);
Vue.use(VScrollSync)
Vue.use(elDragDialog)
Vue.use(Element, {
  size: localStorage.getItem('size') || 'medium'
})
Vue.use(VueParticles)
Vue.use(BaiduMap, {
  ak: 'niXn0VxjzANNyLWQ0FVTxYjhRp1vjjgY'
})
ElSelectTree_Hack.addNewChangeEvent(ElSelectTree)
Vue.use(ElSelectTree)

Vue.prototype.$eventBus = eventBus
Vue.prototype.$moment = moment;
Vue.config.productionTip = false
Vue.config.devtools = false

// 视频播放组件
import VideoPlayer from 'vue-video-player'
import 'vue-video-player/src/custom-theme.css'
import 'video.js/dist/video-js.css'
Vue.use(VideoPlayer)

// 注册全局方法
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
Object.keys(methods).forEach(key => {
  Vue.prototype[`$${key}`] = methods[key];
})
Object.keys(bsComponets).forEach((key) => {
  var name = key.replace(/(\w)/, (v) => v.toUpperCase())
  Vue.component('bs'+name, bsComponets[key])
})
Vue.component('vue-draggable-resizable', VueDraggableResizable)

/**权限指令**/
Vue.directive('has', {
	bind: function(el, binding, vnode) {
    var hasResult = Vue.prototype.$_has(binding.value);
		if (!hasResult) {
      el.style.display = 'none'
		}
	}
});

//权限检查方法
Vue.prototype.$_has = function(value) {
  var result = false;
  // var isRoot = store.getters.isRoot;
  // if (isRoot === 1) {
  //   return true;
  // }
  var permissionStr = store.getters.permissionlist;
	if (permissionStr === undefined || permissionStr === null || permissionStr.length === 0) {
		return false;
  }
  permissionStr.forEach(item => {
    if (item.code === value) {
      result = true;
			return result;
    }
  });
	return result;
};

export const vue = new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
